home *** CD-ROM | disk | FTP | other *** search
- Path: news.luc.edu!user
- From: VArase@varase.it.luc.edu (Verne Arase)
- Newsgroups: comp.lang.c
- Subject: Re: malloc question
- Date: Tue, 12 Mar 1996 10:16:13 -0600
- Organization: LUMC
- Message-ID: <AD6AFF6D9668E8DB7@mcdiala09.it.luc.edu>
- References: <4htonk$350@news.hklink.net> <314318AF.30F@iperbole.bologna.it> <4hvaj4$laj@solutions.solon.com> <AD69AACE9668D78B0@mcdiala09.it.luc.edu> <4i1kq3$2m0@solutions.solon.com>
- NNTP-Posting-Host: 147.126.240.109
-
- In article <4i1kq3$2m0@solutions.solon.com>,
- seebs@solutions.solon.com (Peter Seebach) wrote:
-
- >>In this specific case, however, it _never_ hides an error. If malloc is
- >>used in its standard context, we are simply coercing a slab of memory
- >>aligned to the most stringent boundaries into a pointer of the desired
- >>type.
- >
- >Which does *nothing*, because void pointers always convert to the desired
- >type silently and automatically.
-
- Provided you're not dealing with a pre-ANSI compiler.
-
- >Further, it *did* hide an error in the specific case; <stdlib.h> was not
- >included, and there was no prototype in scope.
- >
- >>Provided the associated header is included (and the memory model doesn't
- >>change through some devious, manual manipulation), you are _always_ safe
- in
- >>coercing a malloc allocated block of memory into the desired pointer
- type.
-
- Then that was what should have been said.
-
- >And you are _always_ redundant doing so, unless you're passing to a
- >varaidic function or one with no prototype in scope.
-
- I had a pre-ANSI compiler which defined malloc as returning char *.
-
- >char is not a signed quantity. char is a quantity which may be signed or
- >unsigned.
-
- Every implementation I've seen makes char signed.
-
- >It's a question of usage. An unspecified short, int, or long is *always*
- >signed, so it is clearly desireable for char to be signed. EOF is
- >negative, and the getc family all return unsigned char or EOF, so it is
- >clearly desireable for char to be unsigned.
-
- While you'd probably want a short, int, or long to be signed, what's the
- percentage of time you actually _want_ char to be signed? And what's the
- percentage of time you gave a hoot whether you had a char * or an unsigned
- char *?
-
- As for the getc routines: don't have any C references here, but don't they
- return an int?
-
- >If you don't put in casts, you will get warnings for any conversion not
- >normally correct. This is helpful.
-
- Depends on the compiler.
-
- I've had IDEs where an uncasted pointer conversion just produced an error
- and stopped the compile.
-
- Anyhow, I accidently let that last post out; I'd been intending to nuke it,
- but forgot and it was transmitted with my last news poll. Sorry for the
- extra traffic in the newsgroup.
-
- ---
- The above are my own opinions, and not those of my employer.
-